<template><div><h2 id="试除法判定质数" tabindex="-1"><a class="header-anchor" href="#试除法判定质数"><span>试除法判定质数</span></a></h2>
<p><img src="@source/notes/基础算法/4.数学知识/1-1.png" alt=""></p>
<h3 id="输入样例" tabindex="-1"><a class="header-anchor" href="#输入样例"><span>输入样例</span></a></h3>
<div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span>2</span></span>
<span class="line"><span>2</span></span>
<span class="line"><span>6</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="输出样例" tabindex="-1"><a class="header-anchor" href="#输出样例"><span>输出样例</span></a></h3>
<div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span>Yes</span></span>
<span class="line"><span>No</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="标准答案" tabindex="-1"><a class="header-anchor" href="#标准答案"><span>标准答案</span></a></h3>
<div class="language-cpp line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="cpp" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#C678DD">#include</span><span style="color:#98C379">&#x3C;iostream></span></span>
<span class="line"><span style="color:#C678DD">using</span><span style="color:#C678DD"> namespace</span><span style="color:#E5C07B"> std</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#C678DD">void</span><span style="color:#61AFEF"> is_prime</span><span style="color:#ABB2BF">(</span><span style="color:#C678DD">int</span><span style="color:#E06C75;font-style:italic"> x</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#C678DD">    if</span><span style="color:#ABB2BF">(x</span><span style="color:#C678DD">&#x3C;</span><span style="color:#D19A66">2</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#ABB2BF">        cout</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#98C379">"No"</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">endl;</span></span>
<span class="line"><span style="color:#C678DD">        return</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF">    }</span></span>
<span class="line"><span style="color:#C678DD">    for</span><span style="color:#ABB2BF">(</span><span style="color:#C678DD">int</span><span style="color:#ABB2BF"> i </span><span style="color:#C678DD">=</span><span style="color:#D19A66"> 2</span><span style="color:#ABB2BF">;i</span><span style="color:#C678DD">&#x3C;=</span><span style="color:#ABB2BF">x</span><span style="color:#C678DD">/</span><span style="color:#ABB2BF">i;i</span><span style="color:#C678DD">++</span><span style="color:#ABB2BF">) </span><span style="color:#C678DD">if</span><span style="color:#ABB2BF">(x</span><span style="color:#C678DD">%</span><span style="color:#ABB2BF">i </span><span style="color:#C678DD">==</span><span style="color:#D19A66"> 0</span><span style="color:#ABB2BF">){</span><span style="color:#7F848E;font-style:italic"> // 推荐写法</span></span>
<span class="line"><span style="color:#ABB2BF">        cout</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#98C379">"No"</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">endl;</span></span>
<span class="line"><span style="color:#C678DD">        return</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF">    }</span></span>
<span class="line"><span style="color:#ABB2BF">    cout</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#98C379">"Yes"</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">endl;</span></span>
<span class="line"><span style="color:#ABB2BF">}</span></span>
<span class="line"><span style="color:#C678DD">int</span><span style="color:#61AFEF"> main</span><span style="color:#ABB2BF">(){</span></span>
<span class="line"><span style="color:#C678DD">    int</span><span style="color:#ABB2BF"> n;cin</span><span style="color:#C678DD">>></span><span style="color:#ABB2BF">n;</span></span>
<span class="line"><span style="color:#C678DD">    while</span><span style="color:#ABB2BF">(n</span><span style="color:#C678DD">--</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#C678DD">        int</span><span style="color:#ABB2BF"> x;cin</span><span style="color:#C678DD">>></span><span style="color:#ABB2BF">x;</span></span>
<span class="line"><span style="color:#61AFEF">        is_prime</span><span style="color:#ABB2BF">(x);</span></span>
<span class="line"><span style="color:#ABB2BF">    }</span></span>
<span class="line"><span style="color:#C678DD">    return</span><span style="color:#D19A66"> 0</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF">}</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h2 id="分解质因数" tabindex="-1"><a class="header-anchor" href="#分解质因数"><span>分解质因数</span></a></h2>
<p><img src="@source/notes/基础算法/4.数学知识/1-2.png" alt=""></p>
<h3 id="输入样例-1" tabindex="-1"><a class="header-anchor" href="#输入样例-1"><span>输入样例</span></a></h3>
<div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span>2</span></span>
<span class="line"><span>6</span></span>
<span class="line"><span>8</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="输出样例-1" tabindex="-1"><a class="header-anchor" href="#输出样例-1"><span>输出样例</span></a></h3>
<div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span>2 1</span></span>
<span class="line"><span>3 1</span></span>
<span class="line"><span></span></span>
<span class="line"><span>2 3</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="参考答案" tabindex="-1"><a class="header-anchor" href="#参考答案"><span>参考答案</span></a></h3>
<div class="language-cpp line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="cpp" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#C678DD">#include</span><span style="color:#98C379">&#x3C;iostream></span></span>
<span class="line"><span style="color:#C678DD">using</span><span style="color:#C678DD"> namespace</span><span style="color:#E5C07B"> std</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#C678DD">void</span><span style="color:#61AFEF"> device</span><span style="color:#ABB2BF">(</span><span style="color:#C678DD">int</span><span style="color:#E06C75;font-style:italic"> x</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#C678DD">    for</span><span style="color:#ABB2BF">(</span><span style="color:#C678DD">int</span><span style="color:#ABB2BF"> i </span><span style="color:#C678DD">=</span><span style="color:#D19A66"> 2</span><span style="color:#ABB2BF">;i</span><span style="color:#C678DD">&#x3C;=</span><span style="color:#ABB2BF">x</span><span style="color:#C678DD">/</span><span style="color:#ABB2BF">i;i</span><span style="color:#C678DD">++</span><span style="color:#ABB2BF">) </span><span style="color:#C678DD">if</span><span style="color:#ABB2BF">(x</span><span style="color:#C678DD">%</span><span style="color:#ABB2BF">i </span><span style="color:#C678DD">==</span><span style="color:#D19A66"> 0</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#C678DD">        int</span><span style="color:#ABB2BF"> s </span><span style="color:#C678DD">=</span><span style="color:#D19A66"> 0</span><span style="color:#ABB2BF">;</span><span style="color:#7F848E;font-style:italic"> // s 是指数 i 是底数</span></span>
<span class="line"><span style="color:#C678DD">        while</span><span style="color:#ABB2BF">(x</span><span style="color:#C678DD">%</span><span style="color:#ABB2BF">i </span><span style="color:#C678DD">==</span><span style="color:#D19A66"> 0</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#ABB2BF">            x</span><span style="color:#C678DD">/=</span><span style="color:#ABB2BF">i;</span></span>
<span class="line"><span style="color:#ABB2BF">            s</span><span style="color:#C678DD">++</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF">        }</span></span>
<span class="line"><span style="color:#ABB2BF">        cout</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">i</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#98C379">" "</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">s</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">endl;</span></span>
<span class="line"><span style="color:#ABB2BF">    }</span></span>
<span class="line"><span style="color:#C678DD">    if</span><span style="color:#ABB2BF">(x</span><span style="color:#C678DD">></span><span style="color:#D19A66">1</span><span style="color:#ABB2BF">) cout</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">x</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#98C379">" "</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#D19A66">1</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">endl;</span></span>
<span class="line"><span style="color:#ABB2BF">    cout</span><span style="color:#C678DD">&#x3C;&#x3C;</span><span style="color:#ABB2BF">endl;</span></span>
<span class="line"><span style="color:#ABB2BF">}</span></span>
<span class="line"><span style="color:#C678DD">int</span><span style="color:#61AFEF"> main</span><span style="color:#ABB2BF">(){</span></span>
<span class="line"><span style="color:#C678DD">    int</span><span style="color:#ABB2BF"> n;cin</span><span style="color:#C678DD">>></span><span style="color:#ABB2BF">n;</span></span>
<span class="line"><span style="color:#C678DD">    while</span><span style="color:#ABB2BF">(n</span><span style="color:#C678DD">--</span><span style="color:#ABB2BF">){</span></span>
<span class="line"><span style="color:#C678DD">        int</span><span style="color:#ABB2BF"> x;cin</span><span style="color:#C678DD">>></span><span style="color:#ABB2BF">x;</span></span>
<span class="line"><span style="color:#61AFEF">        device</span><span style="color:#ABB2BF">(x);</span></span>
<span class="line"><span style="color:#ABB2BF">    }</span></span>
<span class="line"><span style="color:#C678DD">    return</span><span style="color:#D19A66"> 0</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF">}</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h2 id="筛质数" tabindex="-1"><a class="header-anchor" href="#筛质数"><span>筛质数</span></a></h2>
</div></template>


